<template>
  <div class="slider">
    <span class="label">{{ label }}</span>
    <input type="range" :min="min" :max="max" v-model="num" >
    <input type="number" :min="min" :max="max" v-model="num">
  </div>
</template>

<script>
  export default {
    name: 'Slider',
    props: {
      label: {
        type: String,
        required: true
      },
      min: {
        type: Number,
        required: true
      },
      max: {
        type: Number,
        required: true
      },
      value: {
        type: Number,
        required: true
      }
    },
    computed: {
      num: {
        get () {
          return this.value
        },
        set (val) {
          const { min, max } = this
          if (val > max) {
            val = max
          } else if (val < min) {
            val = min
          }
          this.$emit('update:value', Number(val))
        }
      }
    }
  }
</script>

<style lang="less" scoped>
  .slider {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .label {
      min-width: 56px;
    }
    input[type=range] {
      width: 120px;
      block-size: 5px;
    }
    input[type=number] {
      height: 32px;
      width: 55px;
      border-color: #DFE1E3;
      border-style: solid;
      border-width: 1px;
      border-radius: 2px;
      padding-left: 8px;
    }
    input[type=number]:focus {
      border-color: #155BD4;
      border-width: 1px;
      outline: none;
    }
  }
</style>
